import { AvatarEntity } from "db://assets/script/game/demo/ecs/entity/AvatarEntity";
import { NodeComponent } from "db://assets/script/game/demo/ecs/comp/NodeComponent";
import { TransformComponent } from "db://assets/script/game/demo/ecs/comp/TransformComponent";
import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { Vec2 } from "cc";

export class RenderSystem extends ecs.ComblockSystem<AvatarEntity> implements ecs.IEntityEnterSystem, ecs.ISystemUpdate {
    /**
     *  实体第一次会调用
     * @param entity 实体
     */
    entityEnter(entity: AvatarEntity): void {
        entity.nodeComponent.val!.active = true;
    }

    filter(): ecs.IMatcher {
        return ecs.allOf(NodeComponent, TransformComponent);
    }

    update(entity: AvatarEntity): void {
        let vec2 = entity.transformComponent.position;
        entity.nodeComponent.val!.setPosition(vec2.x, vec2.y);
        entity.nodeComponent.val!.angle = entity.transformComponent.angle;
    }
}